package com.echo.serializer;

import com.activeandroid.Model;
import com.activeandroid.serializer.TypeSerializer;
import com.echo.util.ActiveAndroidStrategy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * Created by EchoGe on 2016/6/16.
 */
public abstract  class Serializer extends TypeSerializer {

    protected Gson gson =  new GsonBuilder().setExclusionStrategies(new ActiveAndroidStrategy(null, Model.class)).create();


    //序列化後的Class類型

    @Override

    public Class<?> getSerializedType() {

        return String.class;

    }


    //序列化為String

    @Override

    public Object serialize(Object data) {

        if(data == null){

            return null;

        }

        return  gson.toJson(data);

    }

}
